<?php
namespace app\admin\model;
use think\Loader;
use \think\Model;

class Shop extends Model {
    public function isUsed()
    {
        return $this->is_use==0;//0 是已上架
    }

    public function goodsSave($data,$shop_mark,$image_path)
    {
        $validate = Loader::validate('Shop');
        if(!$validate->check($data)){
            return ['valid'=>0,'message'=>$validate->getError()];
        }else{
            $res = $this->where('categroy_id',$data['categroy_id'])->where('shop_name',$data['shop_name'])->where('member_id',session('member_id'))->count();
            if($res >= 1){
                return ['valid'=>2];
            }
            $data['shop_mark'] = $shop_mark;
            $data['image_path'] = $image_path;
            $money_diff =  intval($data['shop_start_money']) - intval($data['shop_end_money']) ;
            $data['money_diff'] = str_replace("-", "", $money_diff);
            $data['create_time'] = time();

            $result = $this->save($data);
            if(!$result){
                return ['valid'=>1];
            }
        }
    }
}